//import {PERMISSIONS_LIST} from 'constants/api';
import {observable, action, computed, runInAction} from 'mobx';
/* import * as user from 'constants/user';
import {fireGetRequest, getPermissionsList, login} from 'services/app';
import {openNotification} from 'utils';
import {showSuccessMsg} from 'utils'; */

class AppStore {
/*	@observable userInfo;
	@observable isLogined;
	@observable loading;
	@observable authToken;
	@observable userRoles;
	@observable currentProjectStatus;//当前进入访问的项目,用于更新状态进度条
	@observable currentReceivablesStatus;//当前进入访问的应收款,用于更新状态进度条
	@observable  isAdminPage;//是否要进入超级后台页面， 删除 Nav 和 breadcumb
	constructor() {
		const isLogined = window.localStorage.getItem(user.IS_LOGINED);
		const authToken = window.localStorage.getItem(user.AUTH_TOKEN);
		const userRoles = window.localStorage.getItem(user.ROLES_LIST);
		const username = window.localStorage.getItem(user.USER_NAME);
		this.userInfo = username ? user : '';
		this.isLogined = isLogined ? isLogined : false;
		this.userRoles = userRoles;
		this.authToken = authToken ? authToken : null;
		this.loading = false;
		this.currentProjectStatus = null;
		this.currentReceivablesStatus = null;
		this.isAdminPage = window.localStorage.getItem(user.IS_ADMIN_PAGE);
	}

	@action.bound
	loginSubmit = async (values, successcb = () => {
	}) => {
		try {
			this.showLoading();

			const loginRes = await login(values);

			if (loginRes.code === 200) {

				showSuccessMsg('登录成功', 3);

				window.localStorage.setItem(user.USER_NAME, loginRes.name);
				window.localStorage.setItem(user.LOGIN_ACCOUNT, loginRes.loginAccount);
				window.localStorage.setItem(user.AUTH_TOKEN, loginRes.token);
				window.localStorage.setItem(user.IS_LOGINED, true);
				window.localStorage.setItem(user.ROLES_LIST, loginRes.roles.join(','));
				window.localStorage.setItem(user.IS_ADMIN_PAGE, false);

				const perList = await getPermissionsList();
				window.localStorage.setItem(user.PERS_LIST, perList.data ? perList.data.join(',') : '');
				this.userRoles = loginRes.roles.join(',');
				setTimeout(() => {
					this.isLogined = true;
					successcb(loginRes);
				}, 200)


			} else {
				openNotification('error', '登录失败', loginRes.message);
			}
			this.hideLoading();
		}
		catch (error) {
			console.log(error);
		}
	};


	@action.bound
	logout(successcb = () => {
	}) {
		window.localStorage.clear();
		showSuccessMsg('退出成功', 1);
		this.isLogined = false;

		successcb();

	}

	@action.bound
	showAdminPage(isAdminPage) {
		this.isAdminPage = isAdminPage;
		window.localStorage.setItem(user.IS_ADMIN_PAGE, String(isAdminPage));
	}

	//全局加载
	@action
	showLoading() {
		this.loading = true;
	}

	@action
	hideLoading() {
		this.loading = false;
	}

	@action.bound
	setCurrentProjectStatus(project) {
		this.currentProjectStatus = project;
	}

	@action.bound
	setCurrentReceivablesStatus(receivables) {
		this.currentReceivablesStatus = receivables;
	}*/
}

const appStore = new AppStore();

export default appStore;
export {AppStore};
